﻿Imports System
Imports System.Data
Imports System.Data.OleDb

Partial Class AddJobs
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim strJobDescription As String = txtJobDescription.Text.Replace("'", """")
        txtJobDescription.Text = strJobDescription
        lblDate.Text = Now.Date
        'Assume that access_db/Jobs.mdb exists in the root of hosting directory
        'Dim strDataSource As String = Server.MapPath("/access_db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the current directory
        Dim strDataSource As String = Server.MapPath("db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the parent directory of C: drive
        'Dim strDataSource As String = Server.MapPath("../access_db/Jobs.mdb")
        Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                                        "Data source=" & strDataSource
        Dim objConnection As New OleDbConnection(strConnection)
        Dim selectSQL As String = "SELECT jobId FROM tblJobs ORDER BY jobId DESC"
        Dim insertSQL As String = "INSERT INTO tblJobs(jobIndustry,jobSpecTitle,jobCity,jobZip,jobDescription,jobPayRate,jobDate,jobStatus) " & _
                                "VALUES('" & ddlIndustries.SelectedItem.Text & "','" & txtSpecTitle.Text & "','" & _
                                txtCity.Text & "','" & txtZip.Text & "','" & txtJobDescription.Text & "','" & _
                                txtPayRate.Text & "','" & lblDate.Text & "','" & txtStatus.Text & "')"
        Dim intJobId As Integer = 0
        Try
            objConnection.Open()
            Dim objCommand As New OleDbCommand(insertSQL, objConnection)
            objCommand.ExecuteNonQuery()
            objCommand.CommandText = selectSQL
            objCommand.CommandType = CommandType.Text
            objCommand.Connection = objConnection
            intJobId = objCommand.ExecuteScalar()
            lblJobId.Text = intJobId.ToString & ". New job added."
            objConnection.Close()
            objConnection.Dispose()
        Catch ex As Exception
            Response.Write("Error: " & ex.Message)
        End Try
    End Sub

End Class